package it.learn.kafka.producer81.listener;

import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import com.alibaba.cloud.nacos.registry.NacosAutoServiceRegistration;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

// 服务已注册事件
@Slf4j
@Component
public class InstanceRegisteredEventListener implements ApplicationListener<InstanceRegisteredEvent> {

    @Override
    public void onApplicationEvent(InstanceRegisteredEvent event) {
        log.warn("开始处理，服务已注册事件......");
        NacosAutoServiceRegistration serviceRegistration = (NacosAutoServiceRegistration) event.getSource();
        System.out.println("serviceRegistration.toString() = " + serviceRegistration.toString());

        NacosDiscoveryProperties config = (NacosDiscoveryProperties) event.getConfig();
        System.out.println("config.getEndpoint() = " + config.getEndpoint());

    }

}
